<template>
  <section class="todoapp">
    <!-- 除了驼峰, 还可以使用-转换链接 -->
    <TodoHeader :init="init" @add="add"></TodoHeader>
    <TodoMain @del-id="delId" :arr="arr"></TodoMain>
    <TodoFooter :arr="arr"></TodoFooter>
  </section>
</template>

<script>
// 1.0 样式引入
import './styles/base.css'
import './styles/index.css'

import TodoHeader from './components/TodoHeader'
import TodoMain from './components/TodoMain'
import TodoFooter from './components/TodoFooter'
import axios from 'axios'
axios.defaults.baseURL = 'http://liufusong.top:3001'
export default {
  data () {
    return {
      arr: []
    }
  },
  components: {
    TodoHeader,
    TodoMain,
    TodoFooter
  },
  created () {
    this.init()
  },
  methods: {
    init () {
      axios({
        url: '/list'
      }).then(res => {
      // console.log(res.data)
        this.arr = res.data
        console.log(this.arr)
      })
    },
    delId (e) {
      const index = this.arr.findIndex(item => item.id === e)
      this.arr.splice(index, 1)
    },
    add (e) {

    }
  }

}
</script>
